package com.yvtong.Servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import com.yvtong.Service.YonghuManager;
import com.yvtong.entity.yonghu;

/**
 * Servlet implementation class DengluSrevlet
 */
@WebServlet("/DengluSrevlet")
public class DengluSrevlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DengluSrevlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 request.setCharacterEncoding("UTF-8");
			
			String xm = request.getParameter("zhanghao");
			String mm = request.getParameter("mima");
			
			
			YonghuManager m= new YonghuManager();
			yonghu y = m.chaxun(xm);
			if (y != null && y.getMima().equals(mm)) {
				request.getRequestDispatcher("SuccessServlet").forward(request, response);

			} else {
				
				response.sendRedirect("/yvtong/src/views/user/login.html");

			}
			
			response.setContentType("text/json");
			response.setCharacterEncoding("UTF-8");
			PrintWriter out = response.getWriter();
			
			out.flush();
			out.close();
	}

}
